package com.glodon.paas.monitor.server.biz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.glodon.paas.monitor.server.biz.domain.MonitorUserAppEntity;
import com.glodon.paas.monitor.server.biz.mapper.MonitorUserAppMapper;
import com.glodon.paas.monitor.server.biz.service.MonitorUserAppService;
import com.glodon.paas.monitor.server.exception.MonitorException;

@Service("monitorUserAppService")
public class MonitorUserAppServiceImpl implements MonitorUserAppService {

	@Autowired
	private MonitorUserAppMapper	monitorUserAppMapper;

	@Override
	public int deleteByPrimaryKey(Long id) throws MonitorException {
		if (null == id) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"deleteByPrimaryKey UserApp id is null!");
		}
		return monitorUserAppMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(MonitorUserAppEntity record) throws MonitorException {
		if (null == record || null == record.getAppId()) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID, "insert UserApp record is null!");
		}
		return monitorUserAppMapper.insert(record);
	}

	@Override
	public int insertSelective(MonitorUserAppEntity record) throws MonitorException {
		if (null == record || null == record.getAppId()) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"insertSelective UserApp record is null!");
		}
		return monitorUserAppMapper.insertSelective(record);
	}

	@Override
	public MonitorUserAppEntity selectByPrimaryKey(Long id) throws MonitorException {
		if (null == id) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"selectByPrimaryKey UserApp id is null!");
		}
		return monitorUserAppMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(MonitorUserAppEntity record) throws MonitorException {
		if (null == record || null == record.getId()) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"updateByPrimaryKeySelective UserApp record is null!");
		}
		return monitorUserAppMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(MonitorUserAppEntity record) throws MonitorException {
		if (null == record || null == record.getId()) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"updateByPrimaryKey UserApp record is null!");
		}
		return monitorUserAppMapper.updateByPrimaryKey(record);
	}

	@Override
	public List<MonitorUserAppEntity> selectByAppId(Long appId) throws MonitorException {
		if (null == appId) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID, "selectByAppId UserApp appId is null!");
		}
		return monitorUserAppMapper.selectByAppId(appId);
	}

	@Override
	public MonitorUserAppEntity selectByUserId(Long userId) throws MonitorException {
		if (null == userId) {
			throw new MonitorException(MonitorException.ErrorCode.PARAM_INVALID,
					"selectByAppId UserApp userId is null!");
		}
		return monitorUserAppMapper.selectByUserId(userId);
	}
}
